#include <stdio.h>
#include <stdlib.h>
#include <math.h>


//#define DEBUG

#ifdef DEBUG
    #define ASSERT(cond)                                                                        \
    if (!(cond))                                                                                \
    {                                                                                           \
        printf("The state is wrong: %s, file: %s, line: %d\n", #cond, __FILE__, __LINE__);      \
        abort();                                                                                \
    }
#else
    #define ASSERT(cond)
#endif //DEBUG


//#define _EJC

#ifdef  _EJC
    #define OUT if (0)
#else
    #define OUT
#endif // _EJC

/**
    SqrSearch       Checks a number for divisors, which are
                    the squares of any natural numbers (except for 1)

    @param          num         the number for checking
    @param[out]     sqr_div     a number, the square of which is a divisor of num

    @return         0 if the number has a divisor, which is a square of natural number
                    1 if the number doesn't have a divisor, which is a square of natural number
**/

int SqrSearch (long n, long* sqr_div);


int main()
{
    long n = -1, sqr_div = 0;

    OUT printf ("# This program checks a natural number for divisors\n"
                "  which are the squares of any natural numbers (except for 1)\n"
                "# The developer:  Yura Gorishniy      <strausmg@gmail.com>\n"
                "# Version 1.00\n"
                "# The file: %s\n"
                "# The compilaton time: %s, %s\n", strrchr (__FILE__, '\\'), __DATE__, __TIME__);
    OUT printf ("\n" "# Enter the number (type it and press ENTER)\n\n");

    if (scanf ("%ld", &n) != 1) {printf ("# Incorrect input, try again"); return -1;};

    int answer = SqrSearch (n, &sqr_div);
    ASSERT (answer == 1 || answer == 0);

    if (answer)
    {
        printf ("YES");
        OUT printf ("\n" "# The number %ld has a divisor %ld (square of number %d)", n, sqr_div * sqr_div, sqr_div);
    }
    else
    {
        printf ("NO");
        OUT printf ("\n" "# The number %ld doesn't have divisors, which are squares", n);
    }

return 0;
}


int SqrSearch (long num, long* sqr_div)
{
    ASSERT (sqr_div);

    int result = 0;

    if (num > 3)
    {
        long divisor = 2;
        long sqrt_num = floor (sqrt (num));

        while (divisor <= sqrt_num)
        {
            if (num % divisor == 0)
            {
                num = num / divisor;
                if (num % divisor == 0) {*sqr_div = divisor; result = 1; break;}
                sqrt_num = floor (sqrt (num));
            }
            else ++divisor;
        }
    }

return result;
}
